/*
 * PanelWaveInfo.java
 *
 * Created on January 2, 2008, 6:50 PM
 *
 * Copyright (C) 2007-2008  Hylke van der Schaaf
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, in version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

package hextd.UI;

import hextd.sprite.EnemyFactory;
import hextd.util.Context;
import hextd.wave.Wave;
import java.text.DecimalFormat;

/**
 *
 * @author  hylke
 */
public class PanelWaveInfo extends javax.swing.JPanel {
    public static DecimalFormat form = new DecimalFormat("#,###.#");
    private Context context;
    private Object paintLock = new Object();
    
    /** Creates new form PanelWaveInfo */
    public PanelWaveInfo() {
    }
    
    public void setContext(Context c) {
        this.context = c;
        initComponents();
        this.panelEnemy_cur.setContext(c);
        this.panelEnemy_next.setContext(c);
    }
    
    public void clearWaves() {
        this.panelEnemy_cur.clearEnemies();
        this.panelEnemy_next.clearEnemies();
        this.jLabel_cur_level.setText("-");
        this.jLabel_cur_health.setText("-hp");
        this.jLabel_cur_reward.setText("-€");
        this.jLabel_next_level.setText("-");
        this.jLabel_next_health.setText("-hp");
        this.jLabel_next_reward.setText("-€");
    }
    
    public void setWaveCur(Wave w) {
        this.jLabel_cur_level.setText(""+w.getLevel());
        this.jLabel_cur_health.setText(""+this.form.format(w.getBaseHealth())+"hp");
        this.jLabel_cur_reward.setText(""+w.getBasePrice()+"€");
        synchronized(this.paintLock) {
            this.panelEnemy_cur.clearEnemies();
            for (Wave.EnemyInstance e : w.enemySet()) {
                this.panelEnemy_cur.addEnemy(e);
            }
            this.panelEnemy_cur.recalculateSize();
        }
        this.invalidate();
        this.panelEnemy_cur.invalidate();
        this.validate();
    }
    
    public void setWaveNext(Wave w) {
        this.jLabel_next_level.setText(""+w.getLevel());
        this.jLabel_next_health.setText(""+this.form.format(w.getBaseHealth())+"hp");
        this.jLabel_next_reward.setText(""+w.getBasePrice()+"€");
        synchronized(this.paintLock) {
            this.panelEnemy_next.clearEnemies();
            for (Wave.EnemyInstance e : w.enemySet()) {
                this.panelEnemy_next.addEnemy(e);
            }
            this.panelEnemy_next.recalculateSize();
        }
        this.invalidate();
        this.panelEnemy_next.invalidate();
        this.validate();
    }
    
    public void doTick(int gameTime) {
        synchronized(this.paintLock) {
            this.panelEnemy_cur.doTick(gameTime);
            this.panelEnemy_next.doTick(gameTime);
        }
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jLabel_cur_health = new javax.swing.JLabel();
        jLabel_cur_reward = new javax.swing.JLabel();
        panelEnemy_cur = new hextd.UI.PanelEnemy();
        jLabel_next_health = new javax.swing.JLabel();
        jLabel_next_reward = new javax.swing.JLabel();
        panelEnemy_next = new hextd.UI.PanelEnemy();
        jLabel_next_level = new javax.swing.JLabel();
        jLabel_cur_level = new javax.swing.JLabel();

        setBackground(this.context.colors.getColorBackGround());
        setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Current & Next Wave", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Bitstream Vera Sans", 0, 13), this.context.colors.getColorForeGround()));
        setForeground(this.context.colors.getColorForeGround());
        setMaximumSize(new java.awt.Dimension(200, 32767));
        setMinimumSize(new java.awt.Dimension(200, 100));
        setPreferredSize(new java.awt.Dimension(200, 100));
        setLayout(new java.awt.GridBagLayout());

        jLabel_cur_health.setBackground(this.context.colors.getColorBackGround());
        jLabel_cur_health.setForeground(this.context.colors.getColorForeGround());
        jLabel_cur_health.setText("0hp");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
        add(jLabel_cur_health, gridBagConstraints);

        jLabel_cur_reward.setBackground(this.context.colors.getColorBackGround());
        jLabel_cur_reward.setForeground(this.context.colors.getColorForeGround());
        jLabel_cur_reward.setText("0€");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 0.01;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 0);
        add(jLabel_cur_reward, gridBagConstraints);

        panelEnemy_cur.setBorder(null);
        panelEnemy_cur.setMinimumSize(new java.awt.Dimension(30, 30));
        panelEnemy_cur.setLayout(null);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 0.01;
        add(panelEnemy_cur, gridBagConstraints);

        jLabel_next_health.setBackground(this.context.colors.getColorBackGround());
        jLabel_next_health.setForeground(this.context.colors.getColorForeGround());
        jLabel_next_health.setText("0hp");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
        add(jLabel_next_health, gridBagConstraints);

        jLabel_next_reward.setBackground(this.context.colors.getColorBackGround());
        jLabel_next_reward.setForeground(this.context.colors.getColorForeGround());
        jLabel_next_reward.setText("0€");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 0.01;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 0);
        add(jLabel_next_reward, gridBagConstraints);

        panelEnemy_next.setBorder(null);
        panelEnemy_next.setMinimumSize(new java.awt.Dimension(30, 30));
        panelEnemy_next.setLayout(null);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 0.01;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 1, 0);
        add(panelEnemy_next, gridBagConstraints);

        jLabel_next_level.setBackground(this.context.colors.getColorBackGround());
        jLabel_next_level.setForeground(this.context.colors.getColorForeGround());
        jLabel_next_level.setText("0");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5);
        add(jLabel_next_level, gridBagConstraints);

        jLabel_cur_level.setBackground(this.context.colors.getColorBackGround());
        jLabel_cur_level.setForeground(this.context.colors.getColorForeGround());
        jLabel_cur_level.setText("0");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5);
        add(jLabel_cur_level, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel_cur_health;
    private javax.swing.JLabel jLabel_cur_level;
    private javax.swing.JLabel jLabel_cur_reward;
    private javax.swing.JLabel jLabel_next_health;
    private javax.swing.JLabel jLabel_next_level;
    private javax.swing.JLabel jLabel_next_reward;
    private hextd.UI.PanelEnemy panelEnemy_cur;
    private hextd.UI.PanelEnemy panelEnemy_next;
    // End of variables declaration//GEN-END:variables
    
}
